<?php echo "<?php \r\n"; ?>
/**
 * @file			<?php echo $name;?>.api.base.php
 * @CopyRight		(C)1996-2099 SINA Inc.
 * @Project			自游网
 * @Author			liujz <jianzhou@staff.sina.com.cn>
 * @Create Date:	<?php echo date('Y-m-d')."\r\n";?>
 * @Modified By:	jianzhou/<?php echo date('Y-m-d')."\r\n";?>
 * @Brief			<?php echo $desc."\r\n"; ?>
 */
 
class <?php echo $name; ?>_apiBase extends apiBase
{
	var $db;
	var $table;
	
	function __construct() 
	{
		$this->db 	 = vApi::DB();
		$this->table = $this->db->getTable(<?php echo $table; ?>);
	}


	/**
	 * 从DB批量获取内容
	 * @param $ids
	 */
	function batchGet_db($ids) 
	{
		if ( empty($ids) ) { return array(); }
		
		$db	   = vApi::DB();
		$inStr = $db->buildIn($ids);
		$sql   = $db->SQL("SELECT * FROM `%s` WHERE `id` IN ($inStr)", $this->table);
		$rs    = $db->query($sql);
		
		if ( is_array($rs) ) {
			$rs = $this->formatKeyRows($rs, 'id');
		}
		return $rs;
	}
	
	// 批量获取内容
	function batchGet($ids)
	{
		if ( empty($ids) ) {return array(); }
		$rs = $this->mutiCacheCall('batchGet_db', array(''), array('kname'=>'','kvars'=>$ids));
		return $rs;
	}
	
	
	/**
	 * 从DB获取内容
	 * @param $id
	 */
	function get_db($id) 
	{
		if ( empty($id) ) { return array(); }
		
		$db	   = vApi::DB();
		$sql   = $db->SQL("SELECT * FROM `%s` WHERE `id`='%s'", $this->table,$id);
		$rs    = $db->getRow($sql);
		return $this->_buildData($rs);
	}
	
	// 获取内容
	function get($id)
	{
		if ( empty($id) ) {return array(); }
		$rs = $this->cacheCall('get_db', array($id), array('kname'=>'','kvar'=>$id));
		return $rs;
	}	
	
	
	/**
	 * 新增操作
	 * @param array $data
	 */
	function save($id, $data)
	{
		if ( empty($data) ) { return FALSE; }
		
		$rst = $this->db->save($data, $id, <?php echo $table; ?>);
		if ($rst) {
			$this->cacheCall('get_db', array($id), array('kname'=>'','kvar'=>$id), TRUE);
		}
		return $rst;
	}
	
	
	/**
	 * 删除操作
	 * @param bigint $ids
	 */
	function del($ids)
	{
		if ( empty($ids) ) { return FALSE; }
		
		$ids    = is_array($ids) ? $ids : explode(',', $ids);
		$inStr = $this->db->buildIn($ids);
		$rst   = $this->db->execute("Delete From {$this->table} Where id In ($inStr)");
		if ( $rst ) {
			$this->mutiCacheCall('batchGet_db', array(''), array('kname'=>'','kvars'=>$ids), TRUE);
		}
		return $rst;
	}
}